use std::io::Cursor;

use image::{DynamicImage, ImageFormat};

use crate::types::TResult;

// 将图片格式化为字节
pub fn format_to_bytes(img: &DynamicImage, formatter: ImageFormat) -> TResult<Vec<u8>> {
    let mut buff = Cursor::new(vec![]);
    img.write_to(&mut buff, formatter)?;
    Ok(buff.into_inner())
}